package Gui;
import java.awt.Color;
import java.awt.Font;
import java.awt.Rectangle;
import java.awt.SystemColor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import com.toedter.calendar.JDateChooser;

import Entity.Customer;

import controller.CustomerControl;
import controller.LivingAreasControl;
import controller.MarketingTemplateControl;


// TODO: Auto-generated Javadoc
/**
 * The Class AddPotentialCustomer.
 */
public class AddPotentialCustomer extends JPanel{
	
	/** The Constant serialVersionUID. */
	private static final long serialVersionUID = -6400283674228776823L;
	
	/** The Customer id label. */
	public static JLabel CustomerIDLabel;
	
	/** The Customer name label. */
	public static JLabel CustomerNameLabel;
	
	/** The Customer geographic area label. */
	public static JLabel CustomerGeographicAreaLabel;
	
	/** The Customer phone number label. */
	public static JLabel CustomerPhoneNumberLabel;
	
	/** The Customer age label. */
	public static JLabel CustomerAgeLabel;
	
	/** The Order label. */
	public static JLabel OrderLabel;
	
	/** The Order label2. */
	public static JLabel OrderLabel2;
	
	/** The Customer id text field. */
	public static JTextField CustomerIDTextField = null;
	
	/** The Customer name text field. */
	public static JTextField CustomerNameTextField;
	
	/** The Customer geographic area text field. */
	public static JTextField CustomerGeographicAreaTextField = null;
	
	/** The Customer phone number text field. */
	public static JTextField CustomerPhoneNumberTextField = null;
	
	/** The Customer age text field. */
	public static JTextField CustomerAgeTextField = null;
	
	/** The calendar button1. */
	public static JDateChooser calendarButton1;
	
	/** The Addbutton. */
	public static JButton Addbutton;
	
	/** The displaypidbutton. */
	public static JButton displaypidbutton;
	
	/** The displaypidbutton2. */
	public static JButton displaypidbutton2;
	
	/** The displaypidbutton3. */
	public static JButton displaypidbutton3;
	
	/** The confirmation lable. */
	public static JLabel confirmationLable=null;
	
	/** The confirmation lable2. */
	public static JLabel confirmationLable2=null;
	
	/** The confirmation lable3. */
	public static JLabel confirmationLable3=null;
	
	/** The back button. */
	public static JButton backButton = new JButton("Back");
	
	/** The flag. */
	public String flag=null;
	
	/** The text area. */
	public static JTextArea textArea;
	
	/** The text area_1. */
	public static JTextArea textArea_1;
	
	
	public static JTextArea textArea_3;
	
	/** The E customer. */
	private Customer ECustomer;
	
	/** The Ccustomer. */
	private CustomerControl Ccustomer;
	
	/** The CLivingAreas. */
	private LivingAreasControl CLivingAreas;
	
	/** The s. */
	public String s=null;
	private JLabel Orderlabel3;
	private JButton displaybutton3;


;	
	
	/**
	 * Instantiates a new adds the potential customer.
	 */
	public AddPotentialCustomer()
	{
		super();
		AddCustomer();
	}

	/**
	 * Adds the customer.
	 */
	public void AddCustomer(){
		this.setSize( 1500,765 ); //set Frame size
		this.setLayout(null); //set layout
		OrderLabel = new JLabel();     //set new label
		OrderLabel.setBounds(new Rectangle(380, 120, 283, 19));//set label's  size and location
		OrderLabel.setText("Please insert customer details:"); 
		OrderLabel.setFont(new Font("Arial", Font.ITALIC,16)); //set label font and size
		CustomerIDLabel = new JLabel();     //set new label
		CustomerIDLabel.setBounds(new Rectangle(450,170, 113, 18));//set label's  size and location
		CustomerIDLabel.setText("Customer Id:");   // 
		CustomerIDLabel.setFont(new Font("Arial", Font.ITALIC,12)); //set label font and size
		CustomerNameLabel = new JLabel();     //set new label
		CustomerNameLabel.setBounds(new Rectangle(450, 200, 113, 19));//set label's  size and location
		CustomerNameLabel.setText("Customer Name:"); 
		CustomerNameLabel.setFont(new Font("Arial", Font.ITALIC,12)); //set label font and size
		CustomerGeographicAreaLabel = new JLabel();    
		CustomerGeographicAreaLabel.setBounds(new Rectangle(450, 230, 170, 18));//set label's  size and location
		CustomerGeographicAreaLabel.setText("Customer Geographic area:");  
		CustomerGeographicAreaLabel.setFont(new Font("Arial", Font.ITALIC,12)); //set label font and size
		CustomerPhoneNumberLabel = new JLabel();     //set new label
		CustomerPhoneNumberLabel.setBounds(new Rectangle(450, 260, 170, 18));//set label's  size and location
		CustomerPhoneNumberLabel.setText("Customer Phone Number:");   
		CustomerPhoneNumberLabel.setFont(new Font("Arial", Font.ITALIC,12)); //set label font and size
		CustomerAgeLabel = new JLabel();     //set new label
		CustomerAgeLabel.setBounds(new Rectangle(450, 290, 143, 18));//set label's  size and location
		CustomerAgeLabel.setText("Customer Birth Day:");  
		CustomerAgeLabel.setFont(new Font("Arial", Font.ITALIC,12)); //set label font and size
		OrderLabel2 = new JLabel();     //set new label
		OrderLabel2.setBounds(new Rectangle(947, 170, 303, 19));//set label's  size and location
		OrderLabel2.setText("Click Display button to view the customers in Database:"); 
		OrderLabel2.setFont(new Font("Arial", Font.ITALIC,12)); //set label font and size
		this.add(CustomerIDLabel, null);   //add label to the panel
		this.add(CustomerNameLabel, null);   //add label to the panel
		this.add(CustomerGeographicAreaLabel, null);   //add label to the panel
		this.add(CustomerPhoneNumberLabel, null);   //add label to the panel
		this.add(CustomerAgeLabel, null);   //add label to the panel
		this.add(OrderLabel, null);   //add label to the panel
		this.add(OrderLabel2, null);   //add label to the panel
		backButton.setBounds(670, 420, 150, 23);   //set button's size and location
		add(backButton);          // add button to the panel
		this.flag="pid";
		CustomerIDTextField = new JTextField(); 
		CustomerIDTextField.setBounds(new Rectangle(650,170, 127, 17)); //set field's  size and location
		this.add(CustomerIDTextField, null);   // add the field to the panel
		
		CustomerNameTextField = new JTextField(); 
		CustomerNameTextField.setBounds(new Rectangle(650,200, 127, 17)); //set field's  size and location
		this.add(CustomerNameTextField, null);   // add the field to the panel
		
		CustomerGeographicAreaTextField = new JTextField();
		CustomerGeographicAreaTextField.setBounds(new Rectangle(650, 230, 127, 17)); //set field's  size and location
		this.add(CustomerGeographicAreaTextField, null);   // add the field to the panel
		
		CustomerPhoneNumberTextField = new JTextField(); 
		CustomerPhoneNumberTextField.setBounds(new Rectangle(650, 260, 127, 17)); //set field's  size and location
		this.add(CustomerPhoneNumberTextField, null);   // add the field to the panel
		
		
		final JDateChooser calendarButton1 = new JDateChooser();
		calendarButton1.getSpinner().addChangeListener(new ChangeListener() {
			public void stateChanged(ChangeEvent arg0) {
				java.sql.Date sqldate = new java.sql.Date(calendarButton1.getDate().getTime());
			    s=sqldate.toString();
			    System.out.println(s +"test8");
			}

		
		});		
		calendarButton1.setBackground(SystemColor.inactiveCaption);
		calendarButton1.setBounds(650, 290, 200, 20);
	
	    this.add(calendarButton1);
	    
		 Addbutton = new JButton("Add Customer");             
			Addbutton.addActionListener(new ActionListener() {
				@SuppressWarnings("deprecation")
				public void actionPerformed(ActionEvent arg0) {
					if(!(s==null)){	
						ECustomer=new Customer();
						ECustomer.setCId(CustomerIDTextField.getText());
						ECustomer.setcName(CustomerNameTextField.getText());
						ECustomer.setcGeograph(CustomerGeographicAreaTextField.getText());
						ECustomer.setcPhone(CustomerPhoneNumberTextField.getText());
						ECustomer.setAge(s);
						Ccustomer=new CustomerControl();
						if(Ccustomer.CheckDetails(ECustomer.getCId(),ECustomer.getcName(),ECustomer.getAge(),ECustomer.getcGeograph(),ECustomer.getcPhone()))
						{
							Ccustomer.submitCustomer(ECustomer.getCId(),ECustomer.getcName(),ECustomer.getAge(),ECustomer.getcGeograph(),ECustomer.getcPhone());
							confirmationLable.setVisible(true);
						}
						else{ 
							confirmationLable.setVisible(true);
							confirmationLable.setText("Please fill all the fields!!");
						}
					 
					}
					else {
						confirmationLable.setVisible(true);
						confirmationLable.setText("Please Choose Date !");
					}
				}});
			
			Addbutton.setBounds(490, 420, 150, 23);      //set button size
			add(Addbutton);                            //add button to the panel
			
			displaypidbutton2 = new JButton("Display");             
			displaypidbutton2.addActionListener(new ActionListener() {
				@SuppressWarnings("deprecation")
				public void actionPerformed(ActionEvent arg0) {
					Ccustomer=new CustomerControl();
					Ccustomer.ShowCustomers();

				}

			});
			
			displaypidbutton2.setBounds(972, 200, 150, 23);      //set button size
			add(displaypidbutton2);
			
			displaybutton3 = new JButton("Display");
			displaybutton3.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					CLivingAreas=new LivingAreasControl();
					CLivingAreas.ShowLivingAreas2();
				}
			});
			displaybutton3.setBounds(94, 199, 150, 23);
			add(displaybutton3);
			
			confirmationLable = new JLabel("");           // set result label
			confirmationLable.setBounds(490, 460, 350, 150);  // set label's size and location
			add(confirmationLable);                        // add label to the panel
			confirmationLable.setVisible(false); 
			
			textArea = new JTextArea();
			textArea.setBackground(Color.LIGHT_GRAY);
			textArea.setEditable(false);
			textArea.setBounds(958, 234, 229, 486);
			add(textArea);
			
			Orderlabel3 = new JLabel();
			Orderlabel3.setText("Click Display button to view the optional living areas:");
			Orderlabel3.setFont(new Font("Arial", Font.ITALIC, 12));
			Orderlabel3.setBounds(new Rectangle(947, 170, 303, 19));
			Orderlabel3.setBounds(39, 170, 303, 19);
			add(Orderlabel3);
			
			textArea_3 = new JTextArea();
			textArea_3.setEditable(false);
			textArea_3.setBackground(Color.LIGHT_GRAY);
			textArea_3.setBounds(59, 234, 223, 466);
			add(textArea_3);
			
		}
	}
